#include<iostream>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
#include<stdio.h>
using namespace std;
#define N 10

typedef void (*callback_t)();
void Worker()
{
    int cnt = 10;
    while(cnt)
    {
        cout << "I am child process, pid:" << getpid() << " ppid:" << getppid() << " cnt:" << cnt << endl;
        sleep(1);
        cnt--;
    }   
}

void createprocess(int n, callback_t ch)
{

    for(int i = 0; i < n; i++)
    {
        sleep(1);
        pid_t id = fork();
        if(id == 0)
        {   
            cout << "create child process success: " << i << endl;
            ch();
            exit(0);
        }
    }
}

const char* err_string[] = {
    "success",
    "open err",
    "other err"
};
int main()
{
    while(1)
    {
        cout << "I am a normal process, pid:" << getpid() << endl;
        sleep(1);
    }
    //float i = 1/0; 
    //cout << "before:" << errno<< "," << strerror(errno) <<endl;
    //FILE *fp = fopen("./file.txt", "r");
    //cout << "after:" << errno << "," << strerror(errno) <<endl;
    //createprocess(N, Worker);
    //for(int i = 0; i < 200; i++)
    //{
    //    cout << i << ":" << strerror(i) << endl;
    //}
    return 10;
}

